<template>
  <el-container class="home-container">
    <el-header>
      <div>
        <img src="@/assets/logo.png" alt="" class="log" />
        <span class="logname">小凡自习室</span>
      </div>
    </el-header>
    <el-container>
      <!-- unique-opened 独开一栏 -->
      <!-- collapse-transition  折叠动画 ,default-active高亮-->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>

        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409Eff"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="false"
          :default-active="clickMenu"
          router
        >
          <el-submenu :index="i + ''" v-for="(obj, i) in main" :key="i">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span slot="title"> {{ obj.autName }} </span>
            </template>

            <el-menu-item
              v-for="(item, index) in obj.children"
              :key="index"
              :index="'/' + item.path"
            >
              <!--   @click="saveMenu('/' + item.path)" -->
              <i class="el-icon-menu"></i>
              {{ item.autName }}
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      clickMenu: '',
      isCollapse: false, //是否打开侧边栏
      main: [
        {
          autName: 'vue基础',
          children: [
            { autName: '增删改查', path: 'zsgc' },
            { autName: '全选反选', path: 'qxfx' },
            { autName: '轮播图', path: 'lbt' }
          ]
        },
        {
          autName: 'es6复习',
          children: [
            { autName: '防抖节流', path: 'ast' },
            { autName: '数组的方法', path: 'arr' }
          ]
        }
      ]
    }
  },
  created() {
    // .path.slice(1)
    this.clickMenu = this.$route.path
    // console.log(this.clickMenu)
  },
  methods: {
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    }
  }
}
</script>

<style scope>
.home-container {
  height: 98vh;
}
.log {
  width: 50px;
  height: 50px;
  padding: 10px;
  border-radius: 9999px;
}
.logname {
  position: absolute;
  margin: 20px;
}

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;

  color: #fff;
  font-size: 20px;
}
.el-aside {
  background-color: #333744;
}
.el-menu {
  border-right: none;
}
.el-menu-item-group__title {
  padding: 0px;
}

.el-main {
  background-color: #eaedf1;
}

.toggle-button {
  background: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #ffff;
  text-align: center;
  letter-spacing: 5px; /* 文字之间的间距 */
  cursor: pointer; /* 将鼠标改为小手 */
}
</style>